package com.ggs.service.impl;

import com.ggs.DTO.UserDTO;
import com.ggs.mapper.UserMapper;
import com.ggs.pojo.User;
import com.ggs.service.UserService;
import com.ggs.utils.ThreadLocalUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public void register(String username, String password) {
        userMapper.register(username, password);
    }

    @Override
    public User findByName(String username) {
        return userMapper.findByName(username);
    }

    @Override
    public User login(String username, String password) {
        return userMapper.login(username, password);
    }

    @Override
    public void update(UserDTO userDTO) {
        System.out.println(userDTO);
        userMapper.update(userDTO);
    }

    @Override
    public void updateAvatar(String avatarUrl) {
        Map<String, Object> claims = ThreadLocalUtils.get();
        String username = (String) claims.get("username");
        userMapper.updateAvatar(avatarUrl, username);
    }

    @Override
    public void updatePwd(String newPwd, String username) {
        userMapper.updatePwd(newPwd, username);
    }
}
